package com.xiaotu.spider.platformHome.pipeline;

import java.util.List;

import org.springframework.stereotype.Component;

import com.xiaotu.common.model.HomeRecommendModel;
import com.xiaotu.common.util.Constants;
import com.xiaotu.common.util.DataRedisKeyUtils;
import com.xiaotu.spider.APipeline;

import us.codecraft.webmagic.ResultItems;
import us.codecraft.webmagic.Task;

/**
 * @类名 APipeLine
 * @日期 2020年2月27日
 * @作者 wyl
 * @功能 网站首页推荐位pipeline
 */
@Component("HomeRecommendPipeline")
public class HomeRecommendPipeline extends APipeline
{
	@Override
	protected void doProcess(ResultItems resultItems, Task task)
	{
		List<HomeRecommendModel> homeList = resultItems.get(HomeRecommendModel.class.getName());
		if (homeList == null || homeList.isEmpty())
			return;
		
		String key = DataRedisKeyUtils.getKey(Constants.DataRedisKey.HOME_RECOMMEND_YYYYMMDD);
		for (HomeRecommendModel homeModel : homeList){
			cacheHandler.hSet(key, homeModel.getName()+"_"+homeModel.getRankNumber()+"-"+homeModel.getPlatform()+"_"+homeModel.getPlatformSite(), homeModel);
		}
		cacheHandler.setCacheTimeout(key);
	}
}